﻿using B.S.BaseData.ErrorCode;
using B.S.BaseData.ReadAPI.Applications.Commands.Users;
using B.S.BaseData.WriteAPI.Applications.Commands.Users;
using B.S.BaseData.WriteAPI.DTOs.ResponseDto;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.WriteAPI.Controllers.user
{
	/// <summary>
	/// 用户管理
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class UserController : ControllerBase
	{
		CodeController code;
		IMediator _mediator;

		/// <summary>
		/// 构造函数注入
		/// </summary>
		/// <param name="mediator"></param>
		public UserController(IMediator mediator, CodeController code)
		{
			_mediator = mediator;
			this.code = code;
		}

		/// <summary>
		/// 账号密码登录
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<ApiResult<UserDTO>> AccountLogin([FromQuery]UserLoginCommand command)
		{
			var result = await _mediator.Send(command);
			
			return result;
		}

		/// <summary>
		/// 手机号登录
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<ApiResult<UserDTO>> PhoneLogin([FromQuery] UserPhoneLoginCommand command)
		{
			var result = await _mediator.Send(command);
			return result;
		}
	}
}
